﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using StudyCode.Winform.Author;
using StudyCode.Winform.BookShelf;
using StudyCode.Winform.Controls;
using StudyCode.Winform.Properties;

namespace StudyCode.Winform
{
    public partial class MainForm : Form
    {

        List<Button> btnList = new List<Button>();
        public MainForm()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            btnList.Add(btnAccount1);
            btnList.Add(btnOutlay1);
            btnList.Add(btnIncome1);
            btnList.Add(btnAccount2);
            btnList.Add(btnOutlay2);
            btnList.Add(btnIncome2);
            btnMeau_Click(btnAccount1, null);
        }

        private void btnMeau_Click(object sender, EventArgs e)
        {
            //隐藏所有的按钮
            btnList.ForEach(item => item.Visible = true);
            var currentButton = (Button)sender;
            if (currentButton.Name.Contains("btnAccount"))
            {
                btnOutlay1.Hide();
                btnIncome1.Hide();
                btnAccount2.Hide();
            }
            else if (currentButton.Name.Contains("btnOutlay"))
            {
                btnIncome1.Hide();
                btnAccount2.Hide();
                btnOutlay2.Hide();
            }
            else if (currentButton.Name.Contains("btnIncome"))
            {
                btnAccount2.Hide();
                btnOutlay2.Hide();
                btnIncome2.Hide();

            }
            GroupBoxChange(currentButton.Name);
        }


        private void GroupBoxChange(string btnName)
        {
            UserControl customControl = null;
            switch (btnName.Remove(btnName.Length - 1))
            {
                case "btnAccount":
                    customControl = new BookControl();
                    gBoxMain.Text = ResourcesChinese.MainForm_GroupBoxChange_AuthorList;
                    break;
                case "btnOutlay":
                    customControl = new AuthorControl();
                    gBoxMain.Text = ResourcesChinese.MainForm_GroupBoxChange_BookList;
                    break;
                case "btnIncome":
                    customControl = new BookShelfControl();
                    gBoxMain.Text = ResourcesChinese.MainForm_GroupBoxChange_BookShelfList;
                    break;
            }
            if (customControl == null)
                return;

            //注意
            gBoxMain.Controls.Clear();
            customControl.Parent = gBoxMain;
            customControl.Dock = DockStyle.Fill;
            customControl.Show();
        }
    }
}
